package com.peng.rpc.test.socket;

import com.peng.rpc.api.*;
import com.peng.rpc.loadBalance.RoundRobinLoadBalance;
import com.peng.rpc.serializer.CommonSerializer;
import com.peng.rpc.common.client.RpcClient;
import com.peng.rpc.common.client.RpcClientProxy;
import com.peng.rpc.socket.client.SocketRpcClient;

/**
 * socket客户端，定点连接服务器localhost:9000
 * @author Wonderson
 * @email wpp.ds@foxmail.com
 * @date 2022/2/27 20:39
 */
public class SocketTestClient {

    public static void main(String[] args) {
        RpcClient rpcClient = new SocketRpcClient(CommonSerializer.PROTOBUF_SERIALIZER, new RoundRobinLoadBalance());
        RpcClientProxy rpcClientProxy = new RpcClientProxy(rpcClient);
        LoverArg loverArg = new LoverArg();
        loverArg.addLover("sister", "ChuYuan", 16)
                .addLover("yandere", "DonfangLingren", 16)
                .addLover("childhood", "XueZiyuan", 23)
                .addLover("miss", "RuanMubai", 27);
        //创建要代理的对象
        for (int i = 0; i < 10; i++) {
            HelloService helloService = rpcClientProxy.getProxy(HelloService.class);
            String response = helloService.hello(new HelloObject(11, "first message to commit"));
            System.out.println(response);

            HandShakeService handShakeService = rpcClientProxy.getProxy(HandShakeService.class);
            response = handShakeService.greet(new HandShakeArg("Netty", "You are nice!"));
            System.out.println(response);

            LoveService loveService = rpcClientProxy.getProxy(LoveService.class);
            LoverArg.Lover chosen = loveService.marry(loverArg);
            System.out.println("选择了 ==> " + chosen);
        }
    }

}
